package com.iqiju.guagua.photo.wx.mini.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import com.iqiju.guagua.photo.wx.mini.common.Results;
import com.iqiju.guagua.photo.wx.mini.service.WxUserPhotoService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@Api(tags = "上传相册")
@RequestMapping("/wx/photo/file")
public class FileUpLoadController {


    @Autowired
    private WxUserPhotoService wxUserPhotoService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "文件流",required = true,dataType = "MultipartFile",paramType = "body"),
            @ApiImplicitParam(name = "wxMiniAppId",value = "小程序id",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "no",value = "模板编号",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "id",value = "相册id（唯一id接口获取，同相册上传多张使用相同id）",required = true,dataType = "String",paramType = "path")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 0, message = "接口返回成功"),
            @ApiResponse(code = 100, message = "参数错误，请根据提示检查传入的参数是否合法"),
            @ApiResponse(code = 405, message = "token错误"),
            @ApiResponse(code = 401, message = "登录过期或者未登录"),
            @ApiResponse(code = 200, message = "接口返回未知错误，请联系开发人员调试"),
            @ApiResponse(code = 87014, message = "图片检测违规"),
            @ApiResponse(code = 500, message = "接口返回未知错误，请联系开发人员调试")
    })
    @ApiOperation(value = "上传相册图片接口", notes = "访问此接口，进行微信小程序相册图片上传")
    @PostMapping("upload/{wxMiniAppId}/{no}/{id}")
    public Results<Integer> upload(MultipartFile file, @PathVariable String id, @PathVariable String wxMiniAppId, @PathVariable String no){
        log.info("访问上传相册图片接口--------------------------------------------------");
        return wxUserPhotoService.upload(file,id,wxMiniAppId,no);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "userTemplateId",value = "原用户相册id",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "wxMiniAppId",value = "小程序id",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "no",value = "模板编号",required = true,dataType = "String",paramType = "path")
    })
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回结果码",name = "state",dataTypeClass = Integer.class,example = "0",required = true),
                    @DynamicParameter(value = "返回提示信息",name = "message",dataTypeClass = String.class,example = "SUCCESS",required = true),
                    @DynamicParameter(value = "新用户相册id",name = "content",dataTypeClass = String.class),
                    @DynamicParameter(value = "时间戳",name = "time",dataTypeClass = Long.class,example = "1567425139000",required = true)
            })
    )
    @ApiResponses(value = {
            @ApiResponse(code = 0, message = "接口返回成功"),
            @ApiResponse(code = 100, message = "参数错误，请根据提示检查传入的参数是否合法"),
            @ApiResponse(code = 405, message = "token错误"),
            @ApiResponse(code = 401, message = "登录过期或者未登录"),
            @ApiResponse(code = 200, message = "接口返回未知错误，请联系开发人员调试"),
            @ApiResponse(code = 500, message = "接口返回未知错误，请联系开发人员调试")
    })
    @ApiOperation(value = "切换模板接口", notes = "此接口用于照片不变，切换模板时，制作临时相册")
    @PostMapping("change/{userTemplateId}/{wxMiniAppId}/{no}")
    public Results<String> change(@PathVariable String userTemplateId, @PathVariable String wxMiniAppId, @PathVariable String no){
        log.info("访问切换模板接口--------------------------------------------------");
        return wxUserPhotoService.change(userTemplateId,wxMiniAppId,no);
    }

}
